package com.zhuyiyi.mmall.controller;


import com.zhuyiyi.mmall.entity.User;
import com.zhuyiyi.mmall.service.ProductCategoryService;
import com.zhuyiyi.mmall.service.impl.CartServiceImpl;
import com.zhuyiyi.mmall.service.impl.ProductCategoryServiceImpl;
import com.zhuyiyi.mmall.vo.ProductCategoryVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 11
 * @since 2021-05-10
 */
@Controller

@ResponseBody

public class ProductCategoryController {

    @Autowired
    private ProductCategoryServiceImpl service;
    @Autowired
    private CartServiceImpl cartService;

    @GetMapping("/list")
    public ModelAndView list(HttpSession session) {
        ModelAndView modelAndView=new ModelAndView();
        modelAndView.setViewName("main");
        List<ProductCategoryVO> list=new ArrayList<>();
        list=service.getAllProductCategoryVO();
        modelAndView.addObject("list",list);
        User user = (User)session.getAttribute("user");
        if(user!=null) {
            modelAndView.addObject("cartList", cartService.findAllCartVOByUserId(user.getId()));
        }

        service.getAllProductCategoryVO().forEach((System.out::println));
        return modelAndView;
    }

}

